﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLogic;
using System.Data.SqlClient;
using System.Web.Security;

namespace BusinessLogic
{
    [Serializable]
    public class Email : Table
    {
        #region Fields
        private EmailType _emailAddressType;
        private string _emailAddress;
        private bool _isPrimary;
        private bool _isActive;
        #endregion

        #region Methods
        public bool CreateForConversion(Guid constituentID)
        {
            try
            {
                this._id = EmailDataAccess.CreateForConversion(this, constituentID);

                if (this._id != Guid.Empty)
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }

            return false;
        }

        public bool Create(Guid constituentID)
        {
            try
            {
                this._id = EmailDataAccess.Create(this, constituentID);
                
                if(this._id != Guid.Empty)
                {
                    return true;
                }
            }
            catch
            {
                return false;   
            }

            return false;
        }

        public void Delete()
        {
            EmailDataAccess.Delete(this._id);
        }

        public void DeleteByConstituentID(Guid constituentID)
        {
            EmailDataAccess.DeleteByConstituentID(constituentID);
        }

        public static List<Email> GetActiveByConstituentID(Guid constituentID)
        {
            return EmailDataAccess.GetActiveByConstituentID(constituentID);
        }

        public static List<Email> GetAllByConstituentID(Guid constituentID)
        {
            return EmailDataAccess.GetAllByConstituentID(constituentID);
        }

        public static Email GetByID(Guid id)
        {
            return EmailDataAccess.GetByID(id);
        }

        public static Email GetPrimaryByConstituentID(Guid constituentID)
        {
            return EmailDataAccess.GetPrimaryByConstituentID(constituentID);
        }

        public void Update(Guid constituentID)
        {
            EmailDataAccess.Update(this, constituentID);
        }
        #endregion

        #region Properties
        public bool IsActive
        {
            get
            {
                return _isActive;
            }
            set
            {
                _isActive = value;
            }
        }

        public bool IsPrimary
        {
            get
            {
                return _isPrimary;
            }
            set
            {
                _isPrimary = value;
            }
        }

        public EmailType EmailAddressType
        {
            get
            {
                return _emailAddressType;
            }
            set
            {
                _emailAddressType = value;
            }
        }

        public string EmailAddress
        {
            get
            {
                return _emailAddress;
            }
            set
            {
                _emailAddress = value;
            }
        }
        #endregion
    }
}